package org.gpp.proj1.robot.part;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.gpp.proj1.bone.Bone;
import org.gpp.proj1.robot.Robot;
import org.gpp.proj1.robot.action.ActionCache;
import org.gpp.proj1.robot.action.executor.ActionExecutor;
import org.gpp.proj1.robot.modifier.Modifier;
import org.gpp.proj1.robot.part.emissor.Emissor;

/**
 * A generic robot part implementation
 *  
 * @author Paolo Victor, paolovictor@gmail.com
 */
public class EquippedPart extends SparePart implements Part {

	private static final long serialVersionUID = 4960471530786862560L;
	private Map<String, Bone> assignedBoneGroup;
	private Robot parentRobot;
	private String assignedGroupName;
	
	/**
	 * @param name
	 * @param type
	 * @param metadata Map with the part's attributes 
	 * @param modifiers
	 * @param models
	 * @param particleEmissors
	 * @param actions
	 * @param assignedBones
	 * @param parent
	 */
	public EquippedPart( String name, PartType type, int price, Map<String, Integer> metadata, List<Modifier> modifiers, Map<String, String> models, Map<String, String> modelTextures, List<Emissor> particleEmissors, List<String> actions, Robot parentRobot, Map<String, Bone> group ) {
		super( name, type, price, metadata, modifiers, models, modelTextures, particleEmissors, actions );
		
		this.parentRobot = parentRobot;
		this.assignedBoneGroup = group;
	}
	
	/**
	 * @param spare
	 * @param group
	 */
	public EquippedPart( SparePart spare, Robot parentRobot, Map<String, Bone> group ) {
		this( spare.getName(), spare.getPartType(), spare.getPrice(), spare.metadata, spare.modifiers, spare.models, spare.modelTextures, spare.emissorPoints, spare.actions, parentRobot, group );
	}
	
	/**
	/**
	 * @return The list of bones that this part is assigned to
	 */
	public Set<String> getAssignedBoneGroupNames() {
		return assignedBoneGroup.keySet();
	}

	/**
	 * @return The part's parent robot
	 */
	public Robot getParentRobot() {
		return parentRobot;
	}
	

	/**
	 * @see org.gpp.proj1.robot.part.Part#getActionExecutor(java.lang.String)
	 */
	public ActionExecutor getActionExecutor(String action) {
		return this.actions.contains( action ) ?
				new ActionExecutor( this, ActionCache.getInstance().getAction( action ) ):
				null;
	}
	
	public void assignGroup( String group ) {
		this.assignedGroupName = group;
	}

	public String getAssignedGroup() {
		return assignedGroupName;
	}
}